import { NodeSize } from '../config'

export default function ssh(flow) {
  flow.register('Ssh', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M790.869333 364.78781H236.641524v373.686857h554.227809V364.78781zM358.546286 629.296762l-13.775238-13.799619 55.027809-55.02781-55.003428-54.515809 13.726476-13.848381 68.900571 68.339809-68.87619 68.85181z m189.952 2.852571h-101.61981v-19.529143h101.61981v19.529143z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M195.169524 241.322667v538.575238h637.147428V241.322667H195.169524z m41.472 123.465143h554.227809v373.686857H236.641524V364.78781z m554.227809-82.017524v62.488381H236.641524v-62.488381h554.227809z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M706.633143 300.373333h57.758476v19.529143h-57.758476zM344.771048 505.929143l55.003428 54.515809-55.027809 55.02781 13.799619 13.824 68.87619-68.900572-68.900571-68.315428zM446.878476 612.62019h101.61981v19.529143h-101.61981z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '运行SSH命令'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
